﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;


namespace DailyFx.UI
{

	public class ImageConverter : System.Windows.Data.IValueConverter
	{
		public static ImageConverter Instance = new ImageConverter();


		public object Convert( object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null || value == DependencyProperty.UnsetValue)
			{
				return DependencyProperty.UnsetValue;
			}

			return new Image() { Source = ImageSourceConverter.Instance.Convert
											(value, targetType, parameter, culture) as ImageSource
								};
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

	}


	public class ImageSourceConverter : System.Windows.Data.IValueConverter
	{
		public static ImageSourceConverter Instance = new ImageSourceConverter();


		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null || value == DependencyProperty.UnsetValue)
			{
				return DependencyProperty.UnsetValue;
			}

			return Caliburn.Micro.IoC.Get<IUIResourceManager>().GetImage( value.ToString());
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}

	}

}
